<template>
  <div class="login-body">
    <div class="login-container">
      <div class="head">
        <img class="logo" src="../assets/mlogo.png" />
        <div class="name">
          <div class="title">个税审核</div>
          <div class="tips">个税审核系统</div>
        </div>
      </div>
      <el-form label-position="top" @submit="submitForm" :rules="state.rules" :model="state.ruleForm" ref="loginForm"
        class="login-form">
        <el-form-item label="账号" prop="username">
          <el-input type="text" v-model.trim="state.ruleForm.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" class="mt" prop="password">
          <el-input type="password" v-model.trim="state.ruleForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <!-- <div style="color: #333">登录表示您已同意<a>《服务条款》</a></div> -->
          <el-button class="mt" style="width: 100%" type="primary" @click="submitForm">立即登录</el-button>
          <!-- <el-checkbox v-model="state.checked" @change="!state.checked">下次自动登录</el-checkbox> -->
        </el-form-item>
      </el-form>
    </div>
    <div class="beian">
      <el-link href="https://beian.miit.gov.cn" target="_blank">津ICP备2023005582号-1</el-link>
    </div>
  </div>
</template>

<script setup>
import axios from '@/utils/axios'
import { reactive, ref } from 'vue'
import { useRouter } from "vue-router";
import { ElMessage, ElMessageBox } from 'element-plus'
const router = useRouter()
// import { localSet } from '@/utils'
const loginForm = ref(null)
const state = reactive({
  ruleForm: {
    username: '',
    password: ''
  },
  checked: true,
  rules: {
    username: [
      { required: 'true', message: '账号不能为空', trigger: 'blur' }
    ],
    password: [
      { required: 'true', message: '密码不能为空', trigger: 'blur' }
    ]
  }
})
const submitForm = async () => {
  loginForm.value.validate((valid) => {
    if (valid) {
      axios.post('api/user/login', {
        userAccount: state.ruleForm.username,
        userPassword: state.ruleForm.password
      }).then(res => {
        // console.log(res);
        if (res.status == 200) {
          sessionStorage.time = new Date().getTime();
          sessionStorage.isAdmin = res.data.isAdmin;
          router.push({
            name: 'home'
          })
        }else{
          ElMessage.error(res.desc)
        }
      }).catch(res=>{
        
      })
    } else {
      console.log('error submit!!')
      return false;
    }
  })
}
const resetForm = () => {
  loginForm.value.resetFields();
}
</script>

<style scoped>
.login-body {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  margin: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  background-color: #fff;
}
.beian{
  position: fixed;
  bottom: 20px;
  right: 0;
  left: 0;
  text-align: center;
}
.login-container {
  width: 420px;
  height: 500px;
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0px 21px 41px 0px rgba(0, 0, 0, 0.2);
}

.head {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px 0 20px 0;
}

.head img {
  width: 100px;
  height: 100px;
  margin-right: 20px;
}

.head .title {
  font-size: 28px;
  color: #1BAEAE;
  font-weight: bold;
}

.head .tips {
  font-size: 12px;
  color: #999;
  margin-top: 5px;
}

.login-form {
  width: 70%;
  margin: 0 auto;
}

.login-form :deep(.el-form--label-top .el-form-item__label) {
  padding: 0;
}

.login-form :deep(.el-form-item) {
  margin-bottom: 0;
}

.mt {
  margin-top: 20px;
}</style>